/*
 * @Author: SeonHu
 * @Date: 2025-09-16 14:44:19
 * @LastEditors: SeonHu
 * @LastEditTime: 2025-09-23 15:12:13
 * @FilePath: \bg-vben\src\api\iot\index.ts
 * @Description:
 * Copyright © 2020-2025 SANQING Corporation, All rights reserved.
 */
import type {
  DeviceInfo,
  DeviceStatus,
  DeviceVariableIdentity,
  DeviceVariableInfo,
  DeviceVariableResponse,
} from './model';

import type { ErrorMessageMode } from '#/request';

import { request } from '@/utils/request/axios';

/** IoT枚举 */
enum Api {
  /** 获取设备状态集合 */
  GetDeviceStatuses = '/api/iot/getDeviceStatuses',
  /** 获取设备状态 */
  GetDeviceStatus = '/api/iot/getDeviceStatus',

  /** 获取设备集合 */
  GetDevices = '/api/iot/getDevices',
  /** 获取设备 */
  GetDevice = '/api/iot/getDevice',

  /** 根据名称获取设备变量 */
  GetDeviceVariableByName = '/api/iot/getDeviceVariableByName',
  /** 读取设备变量 */
  GetDeviceVariableByIdentity = '/api/iot/getDeviceVariableByIdentity',

  /** 写入设备变量 */
  WriteDeviceVariable = '/api/iot/writeDeviceVariable',
}

// #region 获取设备状态集合
/**
 * 获取设备状态集合
 * @param mode 错误消息模型
 */
export function getDeviceStatuses(mode: ErrorMessageMode = 'message') {
  return request.get<DeviceStatus[]>(
    {
      url: Api.GetDeviceStatuses,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 获取设备状态
/**
 * 获取设备状态
 * @param deviceNames 设备名称
 * @param mode 错误消息模型
 */
export function getDeviceStatus(deviceNames: string[], mode: ErrorMessageMode = 'message') {
  return request.post<DeviceStatus[]>(
    {
      url: Api.GetDeviceStatus,
      params: deviceNames,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 获取设备集合
/**
 * 获取设备集合
 * @param mode 错误消息模型
 */
export function getDevices(mode: ErrorMessageMode = 'message') {
  return request.get<DeviceInfo[]>(
    {
      url: Api.GetDevices,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 获取设备
/**
 * 获取设备
 * @param deviceNames 设备名称
 * @param mode 错误消息模型
 */
export function getDevice(deviceNames: string[], mode: ErrorMessageMode = 'message') {
  return request.post<DeviceInfo[]>(
    {
      url: Api.GetDevice,
      params: deviceNames,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 根据名称获取设备变量
/**
 * 根据名称获取设备变量
 * @param deviceNames 设备名称
 * @param mode 错误消息模型
 */
export function getDeviceVariableByName(deviceNames: string[], mode: ErrorMessageMode = 'message') {
  return request.post<DeviceVariableResponse[]>(
    {
      url: Api.GetDeviceVariableByName,
      params: deviceNames,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 根据标识获取设备变量
/**
 * 根据标识获取设备变量
 * @param dtos 设备变量标识
 * @param mode 错误消息模型
 */
export function getDeviceVariableByIdentity(dtos: DeviceVariableIdentity[], mode: ErrorMessageMode = 'message') {
  return request.post<DeviceVariableResponse[]>(
    {
      url: Api.GetDeviceVariableByIdentity,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 写入设备变量
/**
 * 写入设备变量
 * @param dtos 设备变量信息
 * @param mode 错误消息模型
 */
export function writeDeviceVariable(dtos: DeviceVariableInfo[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.WriteDeviceVariable,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
